about.js ➔ hideBlocks   B
last analyzed

Complexity

Conditions 7

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 3
dl 0
loc 5
rs 8
c 0
b 0
f 0
1
jQuery(document).ready(function ($) {
2
    var timelineBlocks = $('.cd-timeline-block'),
3
        offset = 0.8;
4
5
    // hide timeline blocks which are outside the viewport
6
    hideBlocks(timelineBlocks, offset);
7
8
    // on scolling, show/animate timeline blocks when enter the viewport
9
    $(window).on('scroll', function () {
10
        (!window.requestAnimationFrame)
11
            ? setTimeout(function () { showBlocks(timelineBlocks, offset); }, 100)
12
            : window.requestAnimationFrame(function () { showBlocks(timelineBlocks, offset); });
13
    });
14
15
    function hideBlocks (blocks, offset) {
16
        blocks.each(function () {
17
            ($(this).offset().top > $(window).scrollTop() + $(window).height() * offset) && $(this).find('.cd-timeline-img, .cd-timeline-content').addClass('is-hidden');
18
        });
19
    }
20
21
    function showBlocks (blocks, offset) {
22
        blocks.each(function () {
23
            ($(this).offset().top <= $(window).scrollTop() + $(window).height() * offset && $(this).find('.cd-timeline-img').hasClass('is-hidden')) && $(this).find('.cd-timeline-img, .cd-timeline-content').removeClass('is-hidden').addClass('bounce-in');
24
        });
25
    }
26
});
27